{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">原文地址 https://www.cnblogs.com/green-crosswalk/p/8414134.html\n",
    "\n",
    "gstreamer 使用不当，很容易引起内存泄漏。以下是注意事项：\n",
    "\n",
    "1、gst_element_get_name\n",
    "\n",
    "使用 g_free 释放 name，并设为 null\n",
    "\n",
    "2、g_io_channel_read_line\n",
    "\n",
    "g_free 释放 line，并设为 null\n",
    "\n",
    "3、gst_structure_to_string/gst_caps_to_string\n",
    "\n",
    "g_free 释放返回值，并设为 null\n",
    "\n",
    "4、g_filename_to_uri\n",
    "\n",
    "g_free 释放返回值，并设为 null\n",
    "\n",
    "5、gst_pad_get_name/gst_omx_video_find_nearest_frame\n",
    "\n",
    "不使用时，需要做 unref\n",
    "\n",
    "6、gst_bus_add_watch\n",
    "\n",
    "返回的 watchid 占用 source 资源，有两种释放方式：\n",
    "\n",
    "1）callback 函数返回 FALSE，让 gstreamer 自动释放\n",
    "\n",
    "2）主动调用 g_source_remove 释放；根据经验，只有当 handle message 函数收到 pipeline 切换到 NULL state 后，调用 g_source_remove 释放资源才有效\n",
    "\n",
    "7、g_timeout_add\n",
    "\n",
    "timer 资源通常采用 callback 函数返回 FALSE，让 gst 自动释放\n",
    "\n",
    "8、gst_pad_get_peer\n",
    "\n",
    "返回的 object，带有 ref，因此需要 gst_object_unref 释放\n",
    "\n",
    "9、gst_buffer_map\n",
    "\n",
    "此函数会对 buffer 做 ref，因此需要调用 gst_buffer_unmap\n",
    "\n",
    "10、子类重载父类的 dispose，因此在子类调用结束时调用父类的 dispose 函数，G_OBJECT_CLASS(parent_class)->dispose(object)\n",
    "\n",
    "11、g_object_get 获得 GstElement 类型变量时，会对返回的 element 做 ref 操作，因此 elment 不再使用时，调用 gst_object_unref"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
